package com.fourth_groups.shopping121store.ui.sight.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.fourth_groups.shopping121store.R;
import com.fourth_groups.shopping121store.bean.SightBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/14.
 */

public class SightLvAdapter extends BaseAdapter{

    List<SightBean.DataBean.BlockBean> mBlocks = new ArrayList<>();


    public void setData(List<SightBean.DataBean.BlockBean> blocks) {//设置数据

        this.mBlocks = blocks;


        notifyDataSetChanged();
    }

    public SightLvAdapter() {};

    @Override
    public int getCount() {
        return mBlocks != null ? mBlocks.size()-1 : 0;
    }

    @Override
    public Object getItem(int position) {
        return mBlocks != null ? mBlocks.get(position+1) : null;
    }

    @Override
    public long getItemId(int position) {
        return position+1;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_lv_sight, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //绑定数据
            String img = mBlocks.get(position+1).getItems().get(0).getImage();
            String name = mBlocks.get(position+1).getItems().get(0).getTitle();
            String content = mBlocks.get(position+1).getItems().get(0).getContent();

            //使用glide下载图片
            Glide.with(parent.getContext()).load(img).into(holder.ivSight);

            holder.tvSight.setText(name);
            holder.tvContent.setText(content);


        return convertView;
    }

    static class ViewHolder {
        private ImageView ivSight;
        private TextView tvSight,tvContent;

        public ViewHolder(View contentView) {
            ivSight = (ImageView) contentView.findViewById(R.id.iv_sight);
            tvSight = (TextView) contentView.findViewById(R.id.tv_singht);
            tvContent=(TextView) contentView.findViewById(R.id.tv_content);
        }
    }
}
